package nio;

import java.nio.IntBuffer;
import java.util.Arrays;

/**
 * @Author Klys
 * @Date 2023/6/3 11:56
 * @Description
 * @Version 1.0
 */
public class Demo12 {

    //`slice()`方法会将缓冲区进行划分

    public static void main(String[] args) {
        IntBuffer buffer = IntBuffer.wrap(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 0});
        for (int i = 0; i < 4; i++) buffer.get();
        IntBuffer slice = buffer.slice();
        System.out.println(slice);
        System.out.println("划分之后的情况：" + Arrays.toString(slice.array()));

        System.out.println("划分之后的偏移地址：" + slice.arrayOffset());

        System.out.println("当前position位置：" + slice.position());

        System.out.println("当前limit位置：" + slice.limit());

        while (slice.hasRemaining()) {   //将所有的数据全部挨着打印出来
            System.out.print(slice.get() + ", ");
        }
    }
}
